import DL.SPos;
import statisticAnalysis.LineRegression;

/**
 * Created by xwj on 2018/4/10.
 */
public class Test {

    private static final int MAX_POINTS = 10;

    private double E;

    /**
     * Main program.
     *
     * @param args
     *            the array of runtime arguments
     */
    public static void main(String args[]) {
        LineRegression line = new LineRegression();

        line.addDataPoint(new SPos(1, 136));
        line.addDataPoint(new SPos(2, 143));
        line.addDataPoint(new SPos(3, 132));
        line.addDataPoint(new SPos(4, 142));
        line.addDataPoint(new SPos(5, 147));

        printSums(line);
        printLine(line);
    }

    /**
     * Print the computed sums.
     *
     * @param line
     *            the regression line
     */
    private static void printSums(LineRegression line) {
        System.out.println("\n数据点个数 n = " + line.getDataPointCount());
        System.out.println("\nSum x  = " + line.getSumX());
        System.out.println("Sum y  = " + line.getSumY());
        System.out.println("Sum xx = " + line.getSumXX());
        System.out.println("Sum xy = " + line.getSumXY());
        System.out.println("Sum yy = " + line.getSumYY());

    }

    /**
     * Print the regression line function.
     *
     * @param line
     *            the regression line
     */
    private static void printLine(LineRegression line) {
        System.out.println("\n回归线公式:  y = " + line.getA1() + "x + "
                + line.getA0());
        System.out.println("误差：     R^2 = " + line.getR());
    }

    //y = 2.1x + 133.7   2.1 * 6 + 133.7 = 12.6 + 133.7 = 146.3
    //y = 2.1x + 133.7   2.1 * 7 + 133.7 = 14.7 + 133.7 = 148.4

}
